#include <cmath>
#include <cstring>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int n, m;
namespace justin_jiajia_solution_20_pts {
const int mx = 105;
int d[mx];
int lst[2];
int c(int state) {
  int rr = 0;
  lst[0] = lst[1] = 0;
  for (int i = 0; i < n; ++i) {
    rr += (lst[state >> i & 1] == d[i]) ? lst[state >> i & 1] : 0;
    lst[state >> i & 1] = d[i];
  }
  return rr;
}
void solve() {
  int res = -1;
  for (int i = 0; i < n; ++i) cin >> d[i];
  for (int i = 0; i < (1 << (n)); ++i) res = max(res, c(i));
  cout << res << '\n';
}
};  // namespace justin_jiajia_solution_20_pts
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  freopen("color.in","r",stdin);
  freopen("color.out","w",stdout);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    if (n <= 15)
      justin_jiajia_solution_20_pts::solve();
    else {
      // cout << "N>=15\n";
      justin_jiajia_solution_20_pts::solve();
    }
  }
  cout.flush();
}
// main started at 17:00
// main finished at 17:15
// excepted:20pts